//
//  PromptBoxView.m
//  EMMApp
//
//  Created by Mac on 16/11/7.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "PromptBoxView.h"

@interface PromptBoxView () {
    NSString *_doneName;
    NSString *_clanName;
    NSString *_titleName;
}

@end

@implementation PromptBoxView

- (id)initWithFrame:(CGRect)frame
               done:(NSString *)done
               clan:(NSString *)clan
        titleString:(NSString *)titleString {
    if (self == [super initWithFrame:frame]) {
        _doneName = done;
        _clanName = clan;
        _titleName = titleString;
        [self showUI];
    }
    return  self;
}

- (void)showUI {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
    view.backgroundColor = [UIColor clearColor];
    view.userInteractionEnabled = YES;
    [self addSubview:view];
    
    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(20, (self.bounds.size.height-200)/2, self.bounds.size.width-40, 200)];
    subView.backgroundColor = [UIColor whiteColor];
    subView.userInteractionEnabled = YES;
    subView.userInteractionEnabled = YES;
    subView.layer.masksToBounds = YES;
    subView.layer.cornerRadius = 5;
    [self addSubview:subView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, subView.frame.size.width-40, 150)];
    label.font = [UIFont systemFontOfSize:15];
    label.numberOfLines = 0;
    label.text = _titleName;
    [subView addSubview:label];
    
    UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    doneBtn.frame = CGRectMake(subView.frame.size.width/2, 150, subView.frame.size.width/2, 50);
    doneBtn.backgroundColor = [UIColor orangeColor];
    [doneBtn setTitle:_doneName forState:UIControlStateNormal];
    [doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [doneBtn addTarget:self action:@selector(doneBtnCLick:) forControlEvents:UIControlEventTouchUpInside];
    [subView addSubview:doneBtn];
    
    UIButton *clanBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    clanBtn.frame = CGRectMake(0, 150, subView.frame.size.width/2, 50);
    clanBtn.backgroundColor = [UIColor colorFromHexCode:@"#E4E4E4"];
    [clanBtn setTitle:_clanName forState:UIControlStateNormal];
    [clanBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [clanBtn addTarget:self action:@selector(clanBtnCLick:) forControlEvents:UIControlEventTouchUpInside];
    [subView addSubview:clanBtn];
}

- (void)doneBtnCLick:(UIButton *)btn {
    if (_promptBoxViewBlock) {
        _promptBoxViewBlock(@"1");
    }
}

- (void)clanBtnCLick:(UIButton *)btn {
    if (_promptBoxViewBlock) {
        _promptBoxViewBlock(@"0");
    }
}
@end
